﻿using MaterialTypeRecognition.Shell.AuthenticationServices;
using MaterialTypeRecognition.Shell.AuthenticationServices.Permissions;
using MaterialTypeRecognition.Shell.DeviceServices;
using MaterialTypeRecognition.Shell.EntityFrameworkCore;
using MaterialTypeRecognition.Shell.MesServices;
using MaterialTypeRecognition.Shell.SaveInfoService;
using MaterialTypeRecognition.Shell.Uers;
using MaterialTypeRecognition.Shell.UnitOfWork;
using MaterialTypeRecognition.Shell.Utils;
using MaterialTypeRecognition.Shell.Utils.Devices;
using MaterialTypeRecognition.Shell.ViewModels;
using MaterialTypeRecognition.Shell.Views;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using Prism.Events;
using System.IO;
using WebMiddleware.SaveInfoService;
using WebMiddleware.Store;

namespace MaterialTypeRecognition.Shell
{
    public static class AppServiceRegistry
    {
        public static void OnRegisterServices(this IServiceCollection services)
        {
            services.AddTransient<MainWindow>();
            services.AddTransient<MesConfigurationWindow>();
            services.AddSingleton<TopTipWindow>();
            services.AddTransient<UserManagerWindow>();

            services.AddTransient<MainWindowViewModel>();
            services.AddTransient<UserManagerWindowViewModel>();
            services.AddSingleton<TopTipWindowViewModel>();
            services.AddSingleton<MesConfigurationWindowViewModel>();

            services.AddTransient<IStore<Stream>, TypeSaveInfoStore>();
            // 类型服务注册单例即可哟
            services.AddSingleton<ISaveInfoService, TypeSaveInfoService>();

            services.AddDbContext<MyAppDbContext>();
            services.AddTransient<IUserRepository, UserRepository>();
            services.AddUnitOfWork<MyAppDbContext>();

            services.AddTransient<StopwatchTimer>();
            services.AddTransient<TimesUpTimer>();
            services.AddTransient<IUserService, UserService>();

            services.AddDbContext<MyAppDbContext>();
            //用户仓储
            services.AddTransient<IUserRepository, UserRepository>();
            // 注册工作单元。
            services.AddUnitOfWork<MyAppDbContext>();

            // 添加自动映射。
            services.AddAutoMapper(typeof(AutoMapperConfiguration));
            services.AddSingleton<IEventAggregator, EventAggregator>();
            services.AddSingleton<IAuthenticationService, AuthenticationService>();
            services.AddTransient<IUserAuthenticationService, UserAuthenticationService>();
            services.AddTransient<IJwtBearerService, JwtBearerService>();
            services.AddTransient<IInBoundMesService, InBoundMesService>();
            services.AddSingleton<IAuthorizationHandler, PermissionHandler>();
            services.AddTransient<InBoundSubscriber>();

            // 注册 smart200 服务
            services.AddTransient<SiemensSmart200>();
            services.AddTransient<SiemensSmart200Service>();
        }
    }
}
